package applogic2;

import applogic.FilmHelper;
import model.Film;

public class FilmHelper2 extends DriverBasedHelper implements FilmHelper {

  public FilmHelper2(ApplicationManager2 manager) {
    super(manager.getWebDriver());
  }

  @Override
  public Film create(Film film) {
    pages.internalPage.clickAddFilmButton().ensurePageLoaded()
        .setImdbid(film.getImdb())
    	.setTitle(film.getTitle())
    	.setAKA(film.getNotes())
    	.setYear(film.getYear())
    	.setNotes(film.getNotes())
    	.setDuration(film.getDuration())
    	.setRating(film.getRating())
    	.setIsOwned(film.getIsOwned())
    	.setIsSeen(film.getIsSeen())
    	.setIsLoaned(film.getIsLoaned())
    	.save();
    return film;
  }
  @Override
  public boolean filmAddedSuccess(){
	  return pages.filmViewPage.waitPageLoaded();
  }

  @Override
  public boolean filmAddedFailure(){
	  return pages.filmEditPage.waitPageLoaded();
  }

  @Override
  public String ensureHasMovie(){
	  pages.internalPage.findAllMovies();
	  if (pages.internalPage.noMovies())
		   return create(Film.generateNewFilm()).getTitle();
	  return pages.internalPage.getRandomMovieTitle();
}

  @Override
  public String getRandomMovieTitle(){
	  return pages.internalPage.findAllMovies().getRandomMovieTitle();
  }

  @Override
  public boolean deleteMovie(String movieToDelete){

	  pages.internalPage.clickMovieTitle(movieToDelete)
	  	.clickRemoveMovie()
	  	.searchMovieByKeyword(movieToDelete);

	  return pages.internalPage.noMovies();
  }

  @Override
  public boolean search(String keyword) {
    pages.internalPage.searchMovieByKeyword(keyword);

    return !pages.internalPage.noMovies();

  }

}
